From 27564792afa57c8aee64339152dc58e02f2104ab Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 5 Aug 2025 10:32:39 +0200 Subject: [PATCH] brightnessManager: Make the steps of a BrightnessScale variable This allows each brightness scale to use different number of steps when using stepUp/stepDown. We will use this in the following commits to better deal with backlights which have a limited amount of discrete steps. Part-of: --- js/misc/brightnessManager.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/js/misc/brightnessManager.js b/js/misc/brightnessManager.js index 082487a64..b9d3a540f 100644 --- a/js/misc/brightnessManager.js +++ b/js/misc/brightnessManager.js @@ -5,7 +5,7 @@ import Shell from 'gi://Shell'; import * as Main from '../ui/main.js'; -const SCALE_VALUE_STEP = 0.1; +const SCALE_VALUE_N_STEPS = 10; const SCALE_VALUE_CHANGE_EPSILON = 0.001; const KEYBINDING_SCHEMA = 'org.gnome.shell.keybindings'; @@ -273,12 +273,13 @@ export const BrightnessScale = GObject.registerClass({ false), }, }, class BrightnessScale extends GObject.Object { - constructor(name, value = 1.0) { + constructor(name, value = 1.0, nSteps = SCALE_VALUE_N_STEPS) { super(); this._name = name; this._value = value; this._locked = false; + this._nSteps = nSteps; } get name() { @@ -304,12 +305,16 @@ export const BrightnessScale = GObject.registerClass({ this.notify('locked'); } + get nSteps() { + return this._nSteps; + } + stepUp() { - this._setValue(Math.min(1.0, this._value + SCALE_VALUE_STEP)); + this._setValue(Math.min(1.0, this._value + (1.0 / this._nSteps))); } stepDown() { - this._setValue(Math.max(0.0, this._value - SCALE_VALUE_STEP)); + this._setValue(Math.max(0.0, this._value - (1.0 / this._nSteps))); } cycleUp() { -- 2.39.5